function getHeader(headers, key){
    const filteredHeaders = headers.filter(
        item => item.key === key
    );
    if(filteredHeaders && filteredHeaders[0] && typeof filteredHeaders[0].value === 'string'){
        return filteredHeaders[0].value.trim();
    }
    return null;
}

function setHeader(headers, key, value){
    const filteredHeaders = headers.filter(
        item => item.key === key
    );
    if(filteredHeaders && filteredHeaders[0]){
        filteredHeaders[0].value = value;
    }
    headers.push({key, value});
    return true;
}

module.exports = {
    getHeader,
    setHeader
}